package controller;

import entity.Topic;
import org.json.JSONArray;
import services.ITopicService;
import services.impl.TopicService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/GetAllTopicServlet")
public class GetAllTopicServlet  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out=response.getWriter();

        ITopicService iTopicService=new TopicService();
        List<Topic> getAllTopic=iTopicService.getAllTopic();

        request.setAttribute("kk",getAllTopic);
        request.getRequestDispatcher("index.jsp").forward(request,response);
        /*JSONArray jsonArray=new JSONArray();
        jsonArray.put(getAllTopic);
        out.print(jsonArray);*/
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}

